﻿using System.Collections.Generic;
using System.Diagnostics;
using AutoMapper;
using Hx.DataTransferObject;
using Hx.Domain.Model;
using Hx.Domain.Repositories;
using Hx.Infrastructure.Services;

namespace Hx.Application.Implementation
{
    public class CategoryImplementation
    {
        private readonly ICategoryRepository _categoryRepository;

        public CategoryImplementation()
        {
            _categoryRepository = ServiceLocator.Instance.GetService<ICategoryRepository>();
        }

        public List<CategoryObject> AllCategories()
        {
            var sp = new Stopwatch();
            sp.Start();
            var categories = _categoryRepository.GetAllCategories();
            sp.Stop();
            Debug.WriteLine("SQL:" + sp.ElapsedMilliseconds);

            var result = Mapper.Map<List<Category>, List<CategoryObject>>(categories);
            return result;
        }
    }
}